import {Link, useModel} from "umi";
import {Button, Dropdown, Menu, Space, Typography} from 'antd';
import Cookies from 'js-cookie'
import { history } from 'umi';
import {getUserInfo} from "@/utils/format";
import {EditOutlined, LogoutOutlined, SafetyCertificateOutlined, SettingOutlined} from "@ant-design/icons";

const handleLogout = () => {
  console.log('@logout')
  Cookies.remove('userInfo')
  history.push('/user/login')
}


export default () => {
  const userInfo = getUserInfo()

  let menu;

  if (userInfo.roleid === 2) {
    menu = (
      <Menu
        items={[
          // {
          //   key: '1',
          //   label: (
          //     <Link to='/user/center'>个人中心</Link>
          //   ),
          // },
          {
            key: '1',
            label: (
              <Link to="/fill_circle/management">
                <SettingOutlined /> 学科填报管理
              </Link>
            ),
          },
          {
            key: '2',
            label: (
              <Link to="/changePassword">
                <SafetyCertificateOutlined /> 修改密码
              </Link>
            ),
          },
          {
            key: '3',
            label: (
              <a onClick={handleLogout}>
                <LogoutOutlined /> 退出登录
              </a>
            ),
          },
        ]}
      />
    )
  } else {
    menu = (
      <Menu
        items={[
          // {
          //   key: '1',
          //   label: (
          //     <Link to='/user/center'>个人中心</Link>
          //   ),
          // },
          // {
          //   key: '1',
          //   label: (
          //     <Link to="/fill_circle/management">
          //       学科填报管理
          //     </Link>
          //   ),
          // },
          {
            key: '1',
            label: (
              <Link to="/changePassword">
                <SafetyCertificateOutlined /> 修改密码
              </Link>
            ),
          },
          {
            key: '2',
            label: (
              <a onClick={handleLogout}>
                <LogoutOutlined /> 退出登录
              </a>
            ),
          },
        ]}
      />
    )
  }

  console.log("@@userInfo", userInfo)
  return (
    <Space>
      <Typography.Text style={{color: "white", fontSize: 16,fontFamily:'华文行楷'}}>{userInfo.univ_name}</Typography.Text>
      <Typography.Text style={{color: "white", fontSize: 16}}>{userInfo.discipline_name}</Typography.Text>
      <Dropdown overlay={menu} placement="bottom">
        <Button>{userInfo.username}（{userInfo.role}）</Button>
      </Dropdown>
    </Space>
  )
}
